﻿package com.bizmlib.ui.aquadock
{
	import com.bizmlib.ui.composite.UIComposition;
	
	
	public function AquaDock extends UIComposition
	{
		protected var rollOverIndex:Number;
		protected var activeAreaLength:Number;
		
		
		
		override protected function afterInit():void
		{
			super.afterInit();
			
			activeAreaLength = 200;
			
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		protected function addedToStage(event:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
		}
		protected function mouseMove(event:MouseEvent):void
		{
			updateRollOverIndex();
		}
		protected function updateRollOverIndex():void
		{
			if(activeAreaLength>0)
			{
				rollOverIndex = this.mouseX * visibleItemsList.length / activeAreaLength;
			}
			else
			{
				rollOverIndex = 0;
			}
			redrawItems();
		}
		
		protected function getItemRollOverStrength(itemIndex:Number, rollOverIndex:Number = undefined):Number
		{
			rollOverIndex = rollOverIndex || this.rollOverIndex;
			return Math.max(0, 1 - Math.abs(itemIndex - rollOverIndex));
		}
		
		protected function redrawItems():void
		{
			for(var i:Number=0; i<visibleItemsList.length; i++)
			{
				var item:AquaDockItem = visibleItemsList[i] as AquaDockItem;
				item.rollOverStrength = getItemRollOverStrength(i, rollOverIndex);
			}
			arrangeItems();
		}
		
	}
}